<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js + TypeScript App" />
  </div>
  <el-button>aaaaaa</el-button>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
import { ElButton } from "element-plus"

// const dynamicForm = ref<InstanceType<typeof DynamicForm> | null>(null)

onMounted(() => {
  const ws = new WebSocket("ws://localhost:8888/api/websocket");

  // 当连接打开时执行
  ws.onopen = function () {
    console.log("WebSocket 连接已打开");
    // 向服务器发送一个消息
    ws.send("你好，服务器！");
  };

  // 当接收到服务器消息时执行
  ws.onmessage = function (event) {
    console.log("收到服务器消息: " + event.data);
  };

  // 当连接关闭时执行
  ws.onclose = function () {
    console.log("WebSocket 连接已关闭");
  };

  // 当连接出错时执行
  ws.onerror = function (error) {
    console.log("WebSocket 发生错误: " + error);
  };
}
)


</script>
